import { getListApi } from "@/api/configCenter/clientGrade";
import { getCountryByChannelApi } from "@/api/configCenter/warehouseEntryChannel";
import dayjs from "dayjs";
import { reactive, ref } from "vue";

export default function InitHook() {
  const formState = reactive<Partial<WarehouseEntryChannel.MakeOfferForm>>({
    weightSegmentList: [],
    itemList: [],
    beginTime: dayjs(Date.now()),
    customerLevelList: [],
    customerAdjustmentList: [],
    additionalChargesList: []
  });
  const drawerOpts = reactive<Base.DrawerOpts>({
    title: "",
    width: "1200px",
    component: "",
    passData: {},
    visible: false,
    type: 1
  });
  const dialogOpts = reactive<Base.DialogOpts>({
    title: "",
    width: "520px",
    component: "",
    passData: {},
    visible: false,
    type: 1
  });
  const loading = ref<boolean>(false);
  const countryOpts = ref<Array<Base.GeneraDataType>>([]);
  const customerLevelOpts = ref<Array<Base.GeneraDataType>>([]);
  const getEditBaseRateTime = ref<boolean>(false); //使用编辑离的生效时间
  const getCountryByChannel = (id: string) => {
    return getCountryByChannelApi({ id }).then((res: any) => {
      const { code, data } = res;
      if (code === 200) {
        countryOpts.value = data || [];
      }
    });
  };
  const getCustomerLevelOpts = () => {
    return getListApi({ status: 1, pageNum: 1, pageSize: 99999 }).then((res: any) => {
      const { code, data } = res;
      if (code === 200) {
        customerLevelOpts.value = data.records || [];
      }
    });
  };
  return {
    formState,
    drawerOpts,
    getCountryByChannel,
    countryOpts,
    dialogOpts,
    customerLevelOpts,
    getCustomerLevelOpts,
    loading,
    getEditBaseRateTime
  };
}
